#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    int lengthOfLastWord(string s) {
        int len = 0;
        int n = s.size() - 1;
        while (s[n] == ' ')
        {
            n--;
        }
        for (int i = n; i >= 0; i--)
        {
            if (s[i] != ' ')
            {
                ++len;
            }
            else break;
        }
        return len;
    }
};
int main()
{
    Solution s;
    string str("   fly me   to   the moon  ");
    int ret = s.lengthOfLastWord(str);
    cout << ret << endl;
    return 0;
}